import { bindActionCreators, Dispatch } from 'redux';
import { connect } from 'react-redux';
import Counter from '../components/Resources';
import {
  select,
  add,
  changeFile,
  saveCode
} from '../store/actions/resources';
import {
  changefile,
} from '../store/actions/currentfile';
import { counterStateType } from '../store/reducers/types';

function mapStateToProps(state: counterStateType) {
  return {
    resources: state.resources || [],
    currentfile: state.currentfile
  };
}

function mapDispatchToProps(dispatch: Dispatch) {
  return bindActionCreators(
    {
      select,
      add,
      changeFile,
      saveCode,
      changefile
    },
    dispatch
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(Counter);